package logic

import (
	"context"
	"order_srv/model/mysql"

	"order_srv/internal/svc"
	"order_srv/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateOrderItemLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateOrderItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrderItemLogic {
	return &CreateOrderItemLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CreateOrderItemLogic) CreateOrderItem(in *order.CreateOrderItemRequest) (*order.CreateOrderItemResponse, error) {
	// todo: add your logic here and delete this line
	o := mysql.OrderGoods{
		OrderId:    in.OrderId,
		GoodsId:    in.GoodsId,
		Quantity:   in.Quantity,
		Price:      in.GoodsPrice,
		GoodsTitle: in.GoodsTitle,
		GoodsCover: in.GoodsCover,
	}
	err := o.CreateGoods()
	if err != nil {
		return nil, err
	}
	return &order.CreateOrderItemResponse{}, nil
}
